<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('新增文件管理')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-filedata-add">
        <h4 class="form-header h4">文件管理信息</h4>
        <div class="form-group">
            <label class="col-sm-3 control-label">二进制：</label>
            <div class="col-sm-8">
                <input type="hidden" name="data">
                <div class="file-loading">
                    <input class="form-control file-upload" id="data" name="file" type="file">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">描述：</label>
            <div class="col-sm-8">
                <input name="descp" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">对应知识库表id：</label>
            <div class="col-sm-8">
                <input name="kid" class="form-control" type="text">
            </div>
        </div>
        <h4 class="form-header h4">knowledgepool信息</h4>
        <div class="row">
            <div class="col-sm-12">
                <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i>
                </button>
                <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus">
                    删除</i></button>
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script th:inline="javascript">
    var prefix = ctx + "system/filedata"
    var sexDatas = [[${@dict.getType('sys_user_sex')}]];
    var isAuditDatas = [[${@dict.getType('sys_notice_status')}]];
    $("#form-filedata-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-filedata-add').serialize());
        }
    }

    $(function () {
        var options = {
            pagination: false,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            sidePagination: "client",
            columns: [{
                checkbox: true
            },
                {
                    field: 'index',
                    align: 'center',
                    title: "序号",
                    formatter: function (value, row, index) {
                        var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                        return columnIndex + $.table.serialNumber(index);
                    }
                },
                {
                    field: 'title',
                    align: 'center',
                    title: '标题',
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='knowledgepoolList[%s].title' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'content',
                    align: 'center',
                    title: '内容',
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='knowledgepoolList[%s].content' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'commentCount',
                    align: 'center',
                    title: '评论数',
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='knowledgepoolList[%s].commentCount' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'collectionCount',
                    align: 'center',
                    title: '收藏数',
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='knowledgepoolList[%s].collectionCount' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'author',
                    align: 'center',
                    title: '作者',
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='knowledgepoolList[%s].author' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'uid',
                    align: 'center',
                    title: '作者id',
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='knowledgepoolList[%s].uid' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'sex',
                    align: 'center',
                    title: '性别1：男 2：女',
                    formatter: function (value, row, index) {
                        var name = $.common.sprintf("knowledgepoolList[%s].sex", index);
                        return $.common.dictToSelect(sexDatas, value, name);
                    }
                },
                {
                    field: 'creatTime',
                    align: 'center',
                    title: '创建时间',
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='knowledgepoolList[%s].creatTime' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'lastTime',
                    align: 'center',
                    title: '最近一次修改时间',
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='knowledgepoolList[%s].lastTime' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'keyword',
                    align: 'center',
                    title: '关键词',
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='knowledgepoolList[%s].keyword' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'isAudit',
                    align: 'center',
                    title: '审核状态 未审：0 已审：1',
                    formatter: function (value, row, index) {
                        var name = $.common.sprintf("knowledgepoolList[%s].isAudit", index);
                        return $.common.dictToSelect(isAuditDatas, value, name);
                    }
                },
                {
                    field: 'likeCount',
                    align: 'center',
                    title: '点赞数',
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='knowledgepoolList[%s].likeCount' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'pageViews',
                    align: 'center',
                    title: '浏览次数',
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='knowledgepoolList[%s].pageViews' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'userPower',
                    align: 'center',
                    title: '用户权限',
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='knowledgepoolList[%s].userPower' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'dept',
                    align: 'center',
                    title: '用户部门',
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='knowledgepoolList[%s].dept' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'type',
                    align: 'center',
                    title: '类型1：文本 2：文件',
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='knowledgepoolList[%s].type' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'firstPinYin',
                    align: 'center',
                    title: '姓名首字母',
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='knowledgepoolList[%s].firstPinYin' value='%s'>", index, value);
                        return html;
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var value = $.common.isNotEmpty(row.index) ? row.index : $.table.serialNumber(index);
                        return '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="sub.delRowByIndex(\'' + value + '\')"><i class="fa fa-remove"></i>删除</a>';
                    }
                }]
        };
        $.table.init(options);
    });

    function addRow() {
        var count = $("#" + table.options.id).bootstrapTable('getData').length;
        var row = {
            index: $.table.serialNumber(count),
            title: "",
            content: "",
            commentCount: "",
            collectionCount: "",
            author: "",
            uid: "",
            sex: "",
            creatTime: "",
            lastTime: "",
            keyword: "",
            isAudit: "",
            likeCount: "",
            pageViews: "",
            userPower: "",
            dept: "",
            type: "",
            firstPinYin: "",
        }
        sub.addRow(row);
    }
</script>
</body>
</html>